package org.gwtlive.pointwork.workrequest.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.rpc.AsyncCallback;

import java.util.List;

import org.gwtwidgets.client.ui.EditableLabel;
import org.gwtwidgets.client.ui.PopupCalcPanel;


/**
 * User: fm-sun
 * Date: 2006/07/18
 * Time: 17:09:19
 */
public class WorkRequest implements EntryPoint {
    public void onModuleLoad() {
//        final FlexTable table = new FlexTable();
//        RootPanel.get("slot1").add(table);
//
//        // Make some text boxes.  The password text box is identical to the text
//        // box, except that the input is visually masked by the browser.
//        PasswordTextBox ptb = new PasswordTextBox();
//
//        // Let's make an 80x50 text area to go along with the other two.
//        final TextArea ta = new TextArea();
//        ta.setCharacterWidth(80);
//        ta.setVisibleLines(10);
//        EditableLabel el = new EditableLabel("My Label", new ChangeListener(){
//
//            public void onChange(Widget sender) {
//                 ta.setText(((EditableLabel)sender).getText());
//            }
//        },"OK","Cancel",true);
//        // Add them to the root panel.
//        VerticalPanel panel = new VerticalPanel();
//        panel.add(el);
//        panel.add(ta);
//        panel.add(ptb);
//        RootPanel.get("slot1").add(panel);
//
//
//        final TextBox tb = new TextBox();
//
//        // Let's disallow non-numeric entry in the normal text box.
//        tb.addKeyboardListener(new KeyboardListenerAdapter() {
//            public void onKeyPress(Widget sender, char keyCode, int modifiers) {
//                if (!Character.isDigit(keyCode)) {
//                    // TextBox.cancelKey() suppresses the current keyboard event.
//                    ((TextBox) sender).cancelKey();
//                }
//            }
//        });
//
//		TextBox calcTextBox = new TextBox();
//		Button showCalcBtn = new Button("Show Calc");
//		PopupCalcPanel calc = new PopupCalcPanel(calcTextBox, showCalcBtn);
//
//		RootPanel.get("slot2").add(calcTextBox);
//		RootPanel.get("slot2").add(showCalcBtn);
//		RootPanel.get("slot2").add(calc);

        final FlexTable table = new FlexTable();
        RootPanel.get().add(table);
        AsyncCallback listPublishedWBSCallback = new AsyncCallback() {


            public void onSuccess(Object result) {

                List l = (List) result;
                for (int i = 0; i < l.size(); i++) {
                    WBS wbs = (WBS) l.get(i);
                    table.setText(i, 0, wbs.getDesc());
                    table.setText(i, 1, wbs.getDeadLine().toString());
                    table.setText(i, 2, String.valueOf(wbs.getPoint()));
                }


            }

            public void onFailure(Throwable caught) {

            }
        };

        PublishedWorkService.App.getInstance().listPublishedWBS(listPublishedWBSCallback);

    }
}
